package cn.swust.designpatternlearningplatform.domain.enums;

import cn.swust.designpatternlearningplatform.common.exception.CustomException;

public enum TopicTypeEnum {
    SINGLE("单选题", 1),
    MULTIPLE("多选题", 2),
    JUDGE("判断题", 3),
    SHORT_ANSWER_QUESTION("简答题", 4);
    public final String typeName;
    public final Integer typeId;

    TopicTypeEnum(String typeName, Integer typeId) {
        this.typeName = typeName;
        this.typeId = typeId;
    }

    /**
     * 返回类型名
     *
     * @param choice
     * @return java.lang.String
     * @author Tang
     * @date 2023/5/14 22:07
     **/
    public static String topicType(Integer choice) {
        if (choice == null) {
            return null;
        }
        switch (choice) {
            case 1:
                return TopicTypeEnum.SINGLE.typeName;
            case 2:
                return TopicTypeEnum.MULTIPLE.typeName;
            case 3:
                return TopicTypeEnum.JUDGE.typeName;
            case 4:
                return TopicTypeEnum.SHORT_ANSWER_QUESTION.typeName;
            default:
                throw new CustomException("状态错误");
        }
    }

    /**
     * 返回类型编号
     *
     * @param choice
     * @return java.lang.String
     * @author Tang
     * @date 2023/5/14 22:07
     **/
    public static Integer topicTypeId(String choice) {
        switch (choice) {
            case "单选题":
                return TopicTypeEnum.SINGLE.typeId;
            case "多选题":
                return TopicTypeEnum.MULTIPLE.typeId;
            case "判断题":
                return TopicTypeEnum.JUDGE.typeId;
            case "简答题":
                return TopicTypeEnum.SHORT_ANSWER_QUESTION.typeId;
            default:
                throw new CustomException("状态错误");
        }
    }
}
